<template>
  <div>
    <el-row :gutter="20">
      <el-form
        :model="policyForm"
        :rules="policyRules"
        ref="policyForm"
        label-width="90px"
      >
        <el-col :span="6">
          <el-form-item label="选择通道:" prop="aisleCode">
            <el-select
              size="small"
              v-model="policyForm.aisleCode"
              @change="aisleChange"
              placeholder="请选择通道"
            >
              <el-option
                v-for="item in aisleList"
                :key="item.aisleCode"
                :label="item.aisleName"
                :value="item.aisleCode"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="政策分类:" prop="polTypeCode">
            <el-select
              size="small"
              v-model="policyForm.polTypeCode"
              placeholder="请选择政策分类"
            >
              <el-option
                :label="item.polTypeName"
                :value="item.polTypeCode"
                v-for="item in polTypeClassifyList"
                :key="item.polTypeCode"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="政策名称:" prop="polName">
            <el-input
              size="small"
              v-model="policyForm.polName"
              placeholder="请输入政策名称"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="分润类型:" prop="profitType">
            <el-select
              size="small"
              v-model="policyForm.profitType"
              placeholder="请选择分润类型"
            >
              <el-option
                :label="item.dictValue"
                :value="item.dictKey"
                v-for="(item, index) in polTypeList"
                :key="index"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="政策种类:" prop="polKind">
            <el-select
              size="small"
              v-model="policyForm.polKind"
              placeholder="请选择政策种类"
            >
              <el-option
                :label="item.dictValue"
                :value="item.dictKey"
                v-for="(item, index) in polKindList"
                :key="index"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <div class="haruyuki-scrollbar-70vh haruyuki-p-10">
      <div class="tree aisle-policy-bg" v-if="JSON.stringify(data) !== '{}'">
        <details open>
          <summary class="summary-box">
            <div
              class="tree-item w100 haruyuki-flex-space-between haruyuki-align-items-center"
            >
              <div class="haruyuki-flex1">
                <span class="haruyuki-size-16 policy-ml-3 policy-mr-3"
                  >通道名称：{{ data.aisleName }}</span
                >
              </div>
              <div class="haruyuki-flex-center">
                <div class="haruyuki-mr-10">
                  <span>成本费率：</span>
                  <el-input-number
                    size="mini"
                    v-model="data.aptRate"
                    :precision="4"
                    :step="0.0001"
                    :min="0"
                    :max="1"
                  ></el-input-number>
                  <span> %</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>分润(比例)：</span>
                  <el-input-number
                    size="mini"
                    v-model="data.aptScale"
                    :precision="0"
                    :min="1"
                    :max="100"
                  ></el-input-number>
                  <span> %</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>封顶金额(笔)：</span>
                  <el-input-number
                    size="mini"
                    v-model="data.aptMax"
                    :precision="4"
                    :step="0.1"
                    :min="0"
                  ></el-input-number>
                  <span> ¥</span>
                </div>
                <div class="haruyuki-mr-10">
                  <span>封底金额(笔)：</span>
                  <el-input-number
                    size="mini"
                    v-model="data.aptMin"
                    :precision="4"
                    :step="0.1"
                    :min="0"
                  ></el-input-number>
                  <span> ¥</span>
                </div>
                <div class="policy-mr-3">
                  <el-button
                    type="primary"
                    size="mini"
                    plain
                    @click.stop="submitChildCover(data)"
                    >一键填入</el-button
                  >
                </div>
              </div>
            </div>
          </summary>
          <details v-for="(item, index) in data.levelList" :key="index" open>
            <summary class="haruyuki-flex haruyuki-align-items-center">
              <div class="tree-item haruyuki-flex-center">
                <span class="haruyuki-mr-20">阶梯{{ index + 1 }}</span>
                <div class="haruyuki-flex haruyuki-align-items-center">
                  范围区间：<el-input-number
                    size="mini"
                    v-model="item.aptStartMoney"
                    :precision="4"
                    :step="0.1"
                    :min="0"
                  ></el-input-number
                  ><span>~</span
                  ><el-input-number
                    size="mini"
                    v-model="item.aptEndMoney"
                    :precision="4"
                    :step="0.1"
                    :min="0.1"
                  ></el-input-number>
                  <div
                    class="policy-ml-3 policy-mr-3"
                    v-if="item.id == stateIndex"
                  >
                    <el-button
                      type="text"
                      size="mini"
                      @click="() => ladderAppend(item)"
                    >
                      新增
                    </el-button>
                  </div>
                  <div
                    class="policy-ml-3"
                    v-if="item.id == stateIndex && index != 0"
                  >
                    <el-button
                      type="text"
                      size="mini"
                      @click="() => ladderRemove(index)"
                    >
                      删除
                    </el-button>
                  </div>
                </div>
              </div>
            </summary>
            <!-- 扫码 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.scanRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.scanRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ cItem.compName }}</span>
                </summary>
                <div v-if="cItem.payType == 3">
                  <details open>
                    <summary>
                      <span class="tree-item">银联二维码小额（小于等于1000）</span>
                    </summary>
                    <details v-for="(uItem, uIndex) in ysfRateList(cItem.unionRate, 1)" :key="uIndex" open>
                      <summary>
                        <!-- <span class="tree-item">{{ cItem.compName }}{{ ysfRateTypeName(uItem.ylType) }}</span> -->
                        <span class="tree-item">银联小额{{ ysfRateTypeName(uItem.ylType) }}</span>
                      </summary>
                      <details>
                        <summary>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}成本费率(比例)：</span> -->
                            <span class="input-tree-item-left">银联小额成本费率(比例)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.rate"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">%</span>
                          </div>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}分润(比例)：</span> -->
                            <span class="input-tree-item-left">银联小额分润(比例)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.scale"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">%</span>
                          </div>
                          <div class="tree-item input-tree-item" v-if="uItem.ylType == 2 || uItem.ylType == 4">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}封顶金额(笔)：</span> -->
                            <span class="input-tree-item-left">银联小额封顶金额(笔)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMax"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">元</span>
                          </div>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}封底金额(笔)：</span> -->
                            <span class="input-tree-item-left">银联小额封底金额(笔)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMin"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">元</span>
                          </div>
                        </summary>
                      </details>
                    </details>
                  </details>
                  <details open>
                    <summary>
                      <span class="tree-item">银联二维码大额（大于等于1000）</span>
                    </summary>
                    <details v-for="(uItem, uIndex) in ysfRateList(cItem.unionRate, 2)" :key="uIndex" open>
                      <summary>
                        <!-- <span class="tree-item">{{ cItem.compName }}{{ ysfRateTypeName(uItem.ylType) }}</span> -->
                        <span class="tree-item">银联大额{{ ysfRateTypeName(uItem.ylType) }}</span>
                      </summary>
                      <details>
                        <summary>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}成本费率(比例)：</span> -->
                            <span class="input-tree-item-left">银联大额成本费率(比例)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.rate"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">%</span>
                          </div>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}分润(比例)：</span> -->
                            <span class="input-tree-item-left">银联大额分润(比例)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.scale"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">%</span>
                          </div>
                          <div class="tree-item input-tree-item" v-if="uItem.ylType == 2 || uItem.ylType == 4">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}封顶金额(笔)：</span> -->
                            <span class="input-tree-item-left">银联大额封顶金额(笔)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMax"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">元</span>
                          </div>
                          <div class="tree-item input-tree-item">
                            <!-- <span class="input-tree-item-left">{{ cItem.compName }}封底金额(笔)：</span> -->
                            <span class="input-tree-item-left">银联大额封底金额(笔)：</span>
                            <el-input
                              class="haruyuki-width-100"
                              size="mini"
                              v-model="uItem.aptMin"
                              onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                              @keyup.native="proving($event)"
                            ></el-input>
                            <span class="p_L10">元</span>
                          </div>
                        </summary>
                      </details>
                    </details>
                  </details>
                </div>
                <div v-else>
                  <details open>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}成本费率(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}分润(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}封顶金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">{{ cItem.compName }}封底金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                    </summary>
                  </details>
                </div>
              </details>
            </details>
            <!-- 扫码 END -->
            <!-- 刷卡 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.posRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.posRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ posRateTypeName(cItem.payType) }}</span>
                </summary>
                <!-- payType  刷卡 1.贷记卡 2.借记卡 -->
                <details>
                  <summary>
                    <template v-if="cItem.payType == 1">
                      <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">贷记卡刷卡成本费率(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">贷记卡刷卡分润(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.scale"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">贷记卡刷卡封底金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMin"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                    </template>

                    <template v-if="cItem.payType == 2">
                      <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">借记卡刷卡成本费率(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">借记卡刷卡分润(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.scale"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">借记卡刷卡封顶金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMax"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">借记卡刷卡封底金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMin"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                  </template>
                    
                  </summary>
                </details>
              </details>
            </details>
            <!-- 刷卡 END -->
            <!-- 云闪付 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.ysfRate.typeName }}</span>
              </summary>
              <details open>
                <summary>
                  <span class="tree-item">云闪付优惠（小于等于1000）</span>
                </summary>
                <details v-for="(cItem, cIndex) in ysfRateList(item.typeVO.ysfRate.rateList, 1)" :key="cIndex" open>
                  <summary>
                    <span class="tree-item">云闪付优惠{{ ysfRateTypeName(cItem.ylType) }}</span>
                  </summary>
                  <details>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <!-- <span class="input-tree-item-left">{{ cItem.compName }}成本费率(比例)：</span> -->
                        <span class="input-tree-item-left">云闪付优惠成本费率(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <!-- <span class="input-tree-item-left">{{ cItem.compName }}分润(比例)：</span> -->
                        <span class="input-tree-item-left">云闪付优惠分润(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 4">
                        <span class="input-tree-item-left">云闪付优惠封顶金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">云闪付优惠封底金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                    </summary>
                  </details>
                </details>
              </details>
              <details open>
                <summary>
                  <span class="tree-item">云闪付（大于等于1000）</span>
                </summary>
                <details v-for="(cItem, cIndex) in ysfRateList(item.typeVO.ysfRate.rateList, 2)" :key="cIndex" open>
                  <summary>
                    <span class="tree-item">云闪付{{ ysfRateTypeName(cItem.ylType) }}</span>
                  </summary>
                  <details>
                    <summary>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">云闪付成本费率(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.rate"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">云闪付分润(比例)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.scale"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">%</span>
                      </div>
                      <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 4">
                        <span class="input-tree-item-left">云闪付封顶金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMax"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                      <div class="tree-item input-tree-item">
                        <span class="input-tree-item-left">云闪付封底金额(笔)：</span>
                        <el-input
                          class="haruyuki-width-100"
                          size="mini"
                          v-model="cItem.aptMin"
                          onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                          @keyup.native="proving($event)"
                        ></el-input>
                        <span class="p_L10">元</span>
                      </div>
                    </summary>
                  </details>
                </details>
              </details>
            </details>
            <!-- 云闪付 END -->
            <!-- 快捷 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.quickRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.quickRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">快捷支付</span>
                </summary>
                <details>
                  <summary>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">快捷成本费率(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">快捷分润(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.scale"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                  </summary>
                </details>
              </details>
            </details>
            <!-- 快捷 END -->
            <!-- 垫资 START -->
            <details open>
              <summary>
                <span class="tree-item">{{ item.typeVO.codeAdvanceRate.typeName }}</span>
              </summary>
              <details v-for="(cItem, cIndex) in item.typeVO.codeAdvanceRate.rateList" :key="cIndex" open>
                <summary>
                  <span class="tree-item">{{ codeAdvanceRateTypeName(cItem.ylType) }}</span>
                </summary>
                <details>
                  <summary>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">{{ codeAdvanceRateTypeName(cItem.ylType) }}成本费率(比例)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.rate"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">%</span>
                    </div>
                    <div class="tree-item input-tree-item" v-if="cItem.ylType == 2 || cItem.ylType == 3">
                      <span class="input-tree-item-left">{{ codeAdvanceRateTypeName(cItem.ylType) }}封顶金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMax"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                    <div class="tree-item input-tree-item">
                      <span class="input-tree-item-left">{{ codeAdvanceRateTypeName(cItem.ylType) }}封底金额(笔)：</span>
                      <el-input
                        class="haruyuki-width-100"
                        size="mini"
                        v-model="cItem.aptMin"
                        onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                        @keyup.native="proving($event)"
                      ></el-input>
                      <span class="p_L10">元</span>
                    </div>
                  </summary>
                </details>
              </details>
            </details>
            <!-- 垫资 END -->
          </details>
        </details>
      </div>
    </div>
  </div>
</template>

<script>
import { getDictionary } from "@/api/system/dict";
import { getAisleList } from "@/api/rb-core/oempolicy/oem_policy";
import { detailFrame } from "@/api/rb-core/aislePolicy/aisle_policy";
import { getList } from "@/api/rb-core/policyType/policy_type";

let intId = 1;
export default {
  props: {
    policyForm: Object,
  },
  data() {
    return {
      policyRules: {
        aisleCode: [{ required: true, message: "请选择通道", trigger: "blur" }],
        polTypeCode: [
          { required: true, message: "请选择政策分类", trigger: "blur" },
        ],
        polName: [
          { required: true, message: "请输入政策名称", trigger: "blur" },
        ],
        profitType: [
          { required: true, message: "请选择分润类型", trigger: "blur" },
        ],
        polKind: [
          { required: true, message: "请选择政策种类", trigger: "blur" },
        ],
      },
      aisleList: [], // 一键全入 模板集合
      polTypeList: [],
      polKindList: [],
      polTypeClassifyList: [],
      data: {}, //通道政策 树形数据
      stateIndex: null,
    };
  },
  computed: {
    /* 垫资 ylType 1.扫码垫资 2.贷记卡垫资 3.借记卡垫资 */
    codeAdvanceRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '扫码垫资');
        } else if (val == 2) {
          return (val = '贷记卡垫资');
        } else if (val == 3) {
          return (val = '借记卡垫资');
        }
      };
    },
    /* 刷卡 payType 1.贷记卡 2.借记卡 */
    posRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '贷记卡');
        } else if (val == 2) {
          return (val = '借记卡');
        }
      };
    },
    /* 云闪付 ylType 1.贷记卡小额 2.借记卡小额 3.贷记卡大额 4.借记卡大额 */
    ysfRateTypeName() {
      return (val) => {
        if (val == 1) {
          return (val = '贷记卡');
        } else if (val == 2) {
          return (val = '借记卡');
        } else if (val == 3) {
          return (val = '贷记卡');
        } else if (val == 4) {
          return (val = '借记卡');
        }
      };
    },
    /* 云闪付 大小额分层 */
    ysfRateList() {
      return (unionRate, type) => {
        if (type == 1) {
          return unionRate.filter(item => item.ylType == 1 || item.ylType == 2)
        } else if (type == 2) {
          return unionRate.filter(item => item.ylType == 3 || item.ylType == 4)
        }
      };
    }
  },
  watch: {
    "data.levelList"(val) {
      if (val) {
        if (val.length >= 1) {
          this.stateIndex = val[val.length - 1].id;
        }
      }
    },
  },
  created() {
    this.data = {};
    this.doGetDicts();
    this.getAisleSelect();
  },
  methods: {
    /* 字典 */
    doGetDicts() {
      getDictionary({ code: "profit_type" }).then((res) => {
        this.polTypeList = res.data.data;
      });
      getDictionary({ code: "pol_kind" }).then((res) => {
        this.polKindList = res.data.data;
      });
    },
    /* 通道查询 */
    getAisleSelect() {
      getList("-1", "-1").then((res) => {
        this.polTypeClassifyList = res.data.data.records;
      });
      getAisleList("-1", "-1").then((res) => {
        this.aisleList = res.data.data.records;
      });
    },
    /* 编辑页面详情数据回显 */
    getEditDatail(data) {
      this.policyForm.aisleCode = data.aisleCode;
      this.policyForm.polName = data.polName;
      this.policyForm.polKind = data.polKind + "";
      this.policyForm.profitType = data.profitType + "";
      this.policyForm.polTypeCode = data.polTypeCode;

      let datas = data;
      this.$set(datas, "aptRate", -1);
      this.$set(datas, "aptScale", -1);
      this.$set(datas, "aptMax", -1);
      this.$set(datas, "aptMin", -1);
      for (let i = 0; i < datas.levelList.length; i++) {
        this.$set(datas.levelList[i], "id", intId++);
      }
      this.$nextTick(() => {
        this.data = JSON.parse(JSON.stringify(datas));
      });
    },
    /* 通道选择 回显赋值政策 */
    aisleChange(e) {
      detailFrame(e).then((res) => {
        if (res.data.code == "200") {
          let datas = res.data.data;
          this.$set(datas, "aptRate", -1);
          this.$set(datas, "aptScale", -1);
          this.$set(datas, "aptMax", -1);
          this.$set(datas, "aptMin", -1);
          for (let i = 0; i < datas.levelList.length; i++) {
            this.$set(datas.levelList[i], "id", intId++);
          }
          
          this.$nextTick(() => {
            this.data = JSON.parse(JSON.stringify(datas));
          });
        } else {
          this.$message({
            type: "error",
            message: res.data.message,
          });
        }
      });
    },
    /* 单通道政策模板 一键填入 */
    submitChildCover(data) {
      if (data.aptRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入成本费率",
        });
      } else if (data.aptScale == 0) {
        this.$message({
          type: "warning",
          message: "请输入分润(比例)",
        });
      } else if (data.aptMax == 0) {
        this.$message({
          type: "warning",
          message: "请输入封顶金额(笔)",
        });
      } else if (data.aptMin == 0) {
        this.$message({
          type: "warning",
          message: "请输入封低金额(笔)",
        });
      } else {
        for (let i = 0; i < data.levelList.length; i++) {
          for (const codeAdvanceRate of data.levelList[i].typeVO.codeAdvanceRate.rateList) {
            codeAdvanceRate.rate = data.aptRate;
            codeAdvanceRate.scale = data.aptScale;
            codeAdvanceRate.aptMax = data.aptMax;
            codeAdvanceRate.aptMin = data.aptMin;
          }

          for (const posRate of data.levelList[i].typeVO.posRate.rateList) {
            posRate.rate = data.aptRate;
            posRate.scale = data.aptScale;
            posRate.aptMax = data.aptMax;
            posRate.aptMin = data.aptMin;
          }

          for (const quickRate of data.levelList[i].typeVO.quickRate.rateList) {
            quickRate.rate = data.aptRate;
            quickRate.scale = data.aptScale;
            quickRate.aptMax = data.aptMax;
            quickRate.aptMin = data.aptMin;
          }

          for (const scanRate of data.levelList[i].typeVO.scanRate.rateList) {
            if (scanRate.payType == 3) {
              for (const scanRateItem of scanRate.unionRate) {
                scanRateItem.rate = data.aptRate;
                scanRateItem.scale = data.aptScale;
                scanRateItem.aptMax = data.aptMax;
                scanRateItem.aptMin = data.aptMin;
              }
            } else {
              scanRate.rate = data.aptRate;
              scanRate.scale = data.aptScale;
              scanRate.aptMax = data.aptMax;
              scanRate.aptMin = data.aptMin;
            }
          }

          for (const ysfRate of data.levelList[i].typeVO.ysfRate.rateList) {
            ysfRate.rate = data.aptRate;
            ysfRate.scale = data.aptScale;
            ysfRate.aptMax = data.aptMax;
            ysfRate.aptMin = data.aptMin;
          }
        }
      }
    },
    /* 新增阶梯 */
    ladderAppend(data) {
      let intData = JSON.parse(JSON.stringify(data));
      intData.id = intId++;
      intData.aptStartMoney = intData.aptEndMoney;
      intData.aptEndMoney = intData.aptEndMoney + 1;

      // // 扫码 赋空值
      // for (let j = 0; j < data.productList.length; j++) {
      //   intData.productList[j].id = pid++;
      //   for (
      //     let k = 0;
      //     k < data.productList[j].singlePayInterval.length;
      //     k++
      //   ) {
      //     intData.productList[j].singlePayInterval[k].aptMin = 0;
      //     intData.productList[j].singlePayInterval[k].aptRate = 0;
      //     intData.productList[j].singlePayInterval[k].aptScale = 0;
      //     intData.productList[j].singlePayInterval[k].creditAptMin = 0;
      //     intData.productList[j].singlePayInterval[k].creditAptRate = 0;
      //     intData.productList[j].singlePayInterval[k].creditAptScale = 0;
      //   }
      // }
      this.data.levelList.push(intData);
    },
    /* 删除阶梯 */
    ladderRemove(index) {
      this.data.levelList.splice(index, 1);
    },
    /* input 数值检验 */
    proving(e) {
      var keynum = window.event ? e.keyCode : e.which;   //获取键盘码
      // var keychar = String.fromCharCode(keynum);  //获取键盘码对应的字符
      if (keynum == 189 || keynum == 109) { //禁止输入负数
        e.target.value = 0
      }
      // if (e.target.value.indexOf('.') == 1) { //如果值里面有’.‘的话，进去检测位小数点大于1位的话只保留一位
      //     var x = String(e.target.value).indexOf(".")+4;//得到小数点的位置
      //     var y = String(e.target.value).length - x;//小数点的位数
      //     if(y > 1){
      //         e.target.value = this.getBit(e.target.value, 4)
      //     }
      // }
      if (e.target.value.indexOf(".") != -1) {
        e.target.value = e.target.value.replace(/\.{2,}/g, '.')
        if (e.target.value.length > 6) {
          e.target.value = e.target.value.substr(0, e.target.value.length - 1)
        }
      }
      // if (e.target.value > 1) {
      //     e.target.value = 1
      // }
    },
  },
};
</script>

<style lang="scss" scoped>
.haruyuki-width-100{
  // width: 300px !important;
  width:inherit;
}
.w100{
  width: 100%;
}
.p_L10{
  padding-left: 4px !important;
}
details {
  padding-left: 20px;
}

details summary:focus {
  outline: none;
}

summary {
  width: 100%;
  /* border-bottom: 1px solid #e0eafc; */
  border-bottom: 1px solid #ffffff;
}

summary::-webkit-details-marker {
  display: none;
}
summary:not(:only-child):before {
  content: "\e791";
  color: #606266;
  transition: color 0.15s linear;
  font-size: 16px;
  cursor: pointer;
  margin-right: 6px;
  font-family: element-icons !important;
}
details[open] > summary:not(:only-child):before {
  content: "\e790";
  color: #606266;
  transition: color 0.15s linear;
  font-size: 16px;
  cursor: pointer;
  margin-right: 6px;
  font-family: element-icons !important;
}

.tree {
  /* background: linear-gradient(90deg, #8e9eab 0%, #eef2f3 100%); */
}
/* Haruyuki row height line */
.tree-item {
  height: 40px;
  line-height: 40px;
  transition: all 1s ease 0s;
  user-select: none;
  -moz-user-select: none; /*火狐*/
  -webkit-user-select: none; /*webkit浏览器*/
  -ms-user-select: none; /*IE10*/
  -khtml-user-select: none; /*早期浏览器*/
}
.tree-item:hover {
  background: rgba(195,207,226, 0.2);
  border-radius: 6px;
}

.aisle-policy-bg {
  /* background-color: #e0eafc; */
  background-color: #f9fafc;
  /* padding: 6px 0; */
  padding-left: -10px;
  padding-right: 10px;
  border-radius: 6px;
  /* box-shadow: 0 2px 12px rgba(224, 234, 252, 0.8); */
  box-shadow: 0 2px 12px rgba(153,167,177, 0.4);
  color: #111111;
}

.summary-box {
  display: flex;
  align-items: center;
  padding: 6px 0;
}

.input-tree-item {
  display: flex;
  align-items: center;
}

.input-tree-item-left {
  width: 300px;
}
</style>